﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class DragEventListener : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler, IDropHandler
{
	public delegate void VoidDelegate(GameObject go);
	public delegate void CollosionDelegate(Collider2D collision);
	public VoidDelegate onBeginDrag;
	public VoidDelegate onDrag;
	public VoidDelegate onDrop;
	public VoidDelegate onEndDrag;
	public CollosionDelegate onCollision;

	static public DragEventListener Get(GameObject go)
	{
		DragEventListener listener = go.GetComponent<DragEventListener>();
		if (listener == null) listener = go.AddComponent<DragEventListener>();
		return listener;
	}
	public void OnBeginDrag(PointerEventData eventData)
	{
		if (onBeginDrag != null) onBeginDrag(gameObject);
	}

	public void OnDrag(PointerEventData eventData)
	{
		if (onDrag != null) onDrag(gameObject);
	}

	public void OnDrop(PointerEventData eventData)
	{
		if (onDrop != null) onDrop(gameObject);
	}

	public void OnEndDrag(PointerEventData eventData)
	{
		if (onEndDrag != null) onEndDrag(gameObject);
	}

	public void OnTriggerStay2D(Collider2D collision)
	{
		if (onCollision != null) onCollision(collision);

	}


}
